home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / libgcc2.c < prev    next >
C/C++ Source or Header  |  1994-02-14  |  28KB  |  1,330 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. #ifndef atarist
  28.  
  29. /* It is incorrect to include config.h here, because this file is being
  30.    compiled for the target, and hence definitions concerning only the host
  31.    do not apply.  */
  32.  
  33. #include "tconfig.h"
  34. #include "machmode.h"
  35. #ifndef L_trampoline
  36. #include "gstddef.h"
  37. #endif
  38.  
  39. /* Don't use `fancy_abort' here even if config.h says to use it.  */
  40. #ifdef abort
  41. #undef abort
  42. #endif
  43.  
  44. #else
  45.  
  46. /* For the atari, include the relevant parts of config/m68k.h directly. */
  47.  
  48. #ifndef __mc68000__
  49. #define __mc68000__ 1
  50. #ifdef __M68020__
  51. #define __mc68020__ 1
  52. #endif
  53. #endif
  54.  
  55. #if __GNUC__ < 2
  56. #error This file is for GCC version 2 only.
  57. #endif
  58.  
  59. #ifndef L_trampoline
  60. #include <stddef.h>
  61. #endif
  62.  
  63. #if defined(XFLOAT_ENABLE) && (__GNUC__ > 2 || __GNUC_MINOR__ >= 4)
  64. /* Define for XFmode extended real floating point support.  */
  65. #define LONG_DOUBLE_TYPE_SIZE 96
  66. #else
  67. /* Don't try using XFmode.  */
  68. #define LONG_DOUBLE_TYPE_SIZE 64
  69. #endif
  70.  
  71. /* Define this if most significant bit is lowest numbered
  72.    in instructions that operate on numbered bit-fields.
  73.    This is true for 68020 insns such as bfins and bfexts.  */
  74. #define BITS_BIG_ENDIAN 1
  75.  
  76. /* Define this if most significant word of a multiword number is the lowest
  77.    numbered.  */
  78. /* For 68000 we can decide arbitrarily
  79.    since there are no machine instructions for them.
  80.    So let's be consistent.  */
  81. #define WORDS_BIG_ENDIAN 1
  82.  
  83. /* number of bits in an addressable storage unit */
  84. #define BITS_PER_UNIT 8
  85.  
  86. /* Width in bits of a "word", which is the contents of a machine register.
  87.    Note that this is not necessarily the width of data type `int';
  88.    if using 16-bit ints on a 68000, this would still be 32.
  89.    But on a machine with 16-bit registers, this would be 16.  */
  90. #define BITS_PER_WORD 32
  91.  
  92. /* This is the library routine that is used
  93.    to transfer control from the trampoline
  94.    to the actual nested function.  */
  95.  
  96. /* A colon is used with no explicit operands
  97.    to cause the template string to be scanned for %-constructs.  */
  98. /* The function name __transfer_from_trampoline is not actually used.
  99.    The function definition just permits use of "asm with operands"
  100.    (though the operand list is empty).  */
  101. #define TRANSFER_FROM_TRAMPOLINE                \
  102. void                                \
  103. __transfer_from_trampoline ()                    \
  104. {                                \
  105.   register char *a0 asm ("%a0");                \
  106.   asm (".globl ___trampoline");                    \
  107.   asm ("___trampoline:");                    \
  108.   asm volatile ("move%.l %0,%@" : : "m" (a0[22]));        \
  109.   asm volatile ("move%.l %1,%0" : "=a" (a0) : "m" (a0[18]));    \
  110.   asm ("rts":);                            \
  111. }
  112.  
  113. #endif /* atarist */
  114.  
  115. /* In the first part of this file, we are interfacing to calls generated
  116.    by the compiler itself.  These calls pass values into these routines
  117.    which have very specific modes (rather than very specific types), and
  118.    these compiler-generated calls also expect any return values to have
  119.    very specific modes (rather than very specific types).  Thus, we need
  120.    to avoid using regular C language type names in this part of the file
  121.    because the sizes for those types can be configured to be anything.
  122.    Instead we use the following special type names.  */
  123.  
  124. typedef unsigned int UQItype    __attribute__ ((mode (QI)));
  125. typedef      int SItype    __attribute__ ((mode (SI)));
  126. typedef unsigned int USItype    __attribute__ ((mode (SI)));
  127. typedef         int DItype    __attribute__ ((mode (DI)));
  128. typedef unsigned int UDItype    __attribute__ ((mode (DI)));
  129. typedef     float SFtype    __attribute__ ((mode (SF)));
  130. typedef        float DFtype    __attribute__ ((mode (DF)));
  131. #if LONG_DOUBLE_TYPE_SIZE == 96
  132. typedef        float XFtype    __attribute__ ((mode (XF)));
  133. #endif
  134. #if LONG_DOUBLE_TYPE_SIZE == 128
  135. typedef        float TFtype    __attribute__ ((mode (TF)));
  136. #endif
  137.  
  138. #if BITS_PER_WORD==16
  139. typedef int word_type __attribute__ ((mode (HI)));
  140. #endif
  141. #if BITS_PER_WORD==32
  142. typedef int word_type __attribute__ ((mode (SI)));
  143. #endif
  144. #if BITS_PER_WORD==64
  145. typedef int word_type __attribute__ ((mode (DI)));
  146. #endif
  147.  
  148. /* Make sure that we don't accidentally use any normal C language built-in
  149.    type names in the first part of this file.  Instead we want to use *only*
  150.    the type names defined above.  The following macro definitions insure
  151.    that if we *do* accidentally use some normal C language built-in type name,
  152.    we will get a syntax error.  */
  153.  
  154. #define char bogus_type
  155. #define short bogus_type
  156. #define int bogus_type
  157. #define long bogus_type
  158. #define unsigned bogus_type
  159. #define float bogus_type
  160. #define double bogus_type
  161.  
  162. #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  163.  
  164. /* DIstructs are pairs of SItype values in the order determined by
  165.    WORDS_BIG_ENDIAN.  */
  166.  
  167. #if WORDS_BIG_ENDIAN
  168.   struct DIstruct {SItype high, low;};
  169. #else
  170.   struct DIstruct {SItype low, high;};
  171. #endif
  172.  
  173. /* We need this union to unpack/pack DImode values, since we don't have
  174.    any arithmetic yet.  Incoming DImode parameters are stored into the
  175.    `ll' field, and the unpacked result is read from the struct `s'.  */
  176.  
  177. typedef union
  178. {
  179.   struct DIstruct s;
  180.   DItype ll;
  181. } DIunion;
  182.  
  183. #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
  184.  
  185. #include "longlong.h"
  186.  
  187. #endif /* udiv or mul */
  188.  
  189. extern DItype __fixunssfdi (SFtype a);
  190. extern DItype __fixunsdfdi (DFtype a);
  191. #if LONG_DOUBLE_TYPE_SIZE == 96
  192. extern DItype __fixunsxfdi (XFtype a);
  193. #endif
  194. #if LONG_DOUBLE_TYPE_SIZE == 128
  195. extern DItype __fixunstfdi (TFtype a);
  196. #endif
  197.  
  198. #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
  199. #if defined (L_divdi3) || defined (L_moddi3)
  200. static inline
  201. #endif
  202. DItype
  203. __negdi2 (u)
  204.      DItype u;
  205. {
  206.   DIunion w;
  207.   DIunion uu;
  208.  
  209.   uu.ll = u;
  210.  
  211.   w.s.low = -uu.s.low;
  212.   w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
  213.  
  214.   return w.ll;
  215. }
  216. #endif
  217.  
  218. #ifdef L_lshldi3
  219. DItype
  220. __lshldi3 (u, b)
  221.      DItype u;
  222.      SItype b;
  223. {
  224.   DIunion w;
  225.   SItype bm;
  226.   DIunion uu;
  227.  
  228.   if (b == 0)
  229.     return u;
  230.  
  231.   uu.ll = u;
  232.  
  233.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  234.   if (bm <= 0)
  235.     {
  236.       w.s.low = 0;
  237.       w.s.high = (USItype)uu.s.low << -bm;
  238.     }
  239.   else
  240.     {
  241.       USItype carries = (USItype)uu.s.low >> bm;
  242.       w.s.low = (USItype)uu.s.low << b;
  243.       w.s.high = ((USItype)uu.s.high << b) | carries;
  244.     }
  245.  
  246.   return w.ll;
  247. }
  248. #endif
  249.  
  250. #ifdef L_lshrdi3
  251. DItype
  252. __lshrdi3 (u, b)
  253.      DItype u;
  254.      SItype b;
  255. {
  256.   DIunion w;
  257.   SItype bm;
  258.   DIunion uu;
  259.  
  260.   if (b == 0)
  261.     return u;
  262.  
  263.   uu.ll = u;
  264.  
  265.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  266.   if (bm <= 0)
  267.     {
  268.       w.s.high = 0;
  269.       w.s.low = (USItype)uu.s.high >> -bm;
  270.     }
  271.   else
  272.     {
  273.       USItype carries = (USItype)uu.s.high << bm;
  274.       w.s.high = (USItype)uu.s.high >> b;
  275.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  276.     }
  277.  
  278.   return w.ll;
  279. }
  280. #endif
  281.  
  282. #ifdef L_ashldi3
  283. DItype
  284. __ashldi3 (u, b)
  285.      DItype u;
  286.      SItype b;
  287. {
  288.   DIunion w;
  289.   SItype bm;
  290.   DIunion uu;
  291.  
  292.   if (b == 0)
  293.     return u;
  294.  
  295.   uu.ll = u;
  296.  
  297.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  298.   if (bm <= 0)
  299.     {
  300.       w.s.low = 0;
  301.       w.s.high = (USItype)uu.s.low << -bm;
  302.     }
  303.   else
  304.     {
  305.       USItype carries = (USItype)uu.s.low >> bm;
  306.       w.s.low = (USItype)uu.s.low << b;
  307.       w.s.high